import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_module/common/base/base_list.dart';
import 'package:flutter_module/common/base/base_page.dart';
import 'package:flutter_module/common/widget/empty_view/empty_view.dart';

class EmptyPage extends BaseStateFulWidget {
  const EmptyPage({Key? key}) : super(key: key);

  @override
  BaseState<StatefulWidget> buildState() {
    return _EmptyPageState();
  }
}

class _EmptyPageState extends BaseState<EmptyPage> with BasePage, ListBehavior {
  @override
  Widget createView(BuildContext context) {
    return ListView.builder(itemBuilder: (content, index) {
      return Container(
        height: 80,
        color: Colors.primaries[index],
      );
    });
  }

  @override
  String get appBarTitle => 'EmptyDemo';

  @override
  OnRefreshCallback get onRefresh => () async {
        Future.delayed(Duration(
          milliseconds: 3000,
        )).then((value) {
          esRefreshController.finishRefresh(success: true);
          setState(() {
            isEmpty = true;
          });
        });
      };
  @override
  OnRefreshCallback get onLoad => () async {
        Future.delayed(Duration(milliseconds: 3000)).then((value) {
          esRefreshController.finishLoad();
          print('开始上拉');
        });
      };

  @override
  createEmptyView() {
    return EmptyView(
      reloadAction: reloadPress,
      message: Text('暂无数据'),
    );
  }

  @override
  reloadPress() {
    setState(() {
      isEmpty = false;
    });
  }
}
